package cn.wyj.org.controller;

import cn.wyj.basic.anno.LogAnno;
import cn.wyj.basic.util.AjaxResult;
import cn.wyj.basic.util.PageList;
import cn.wyj.org.domain.Systemdictionarytype;
import cn.wyj.org.query.SystemdictionarytypeQuery;
import cn.wyj.org.service.SystemdictionarydetailService;
import cn.wyj.org.service.SystemdictionarytypeService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/stype")
public class SystemdictionarytypeController {

    @Autowired
    private SystemdictionarytypeService systemdictionarytypeService;

    @Autowired
    private SystemdictionarydetailService systemdictionarydetailService;

    // 查询所有类型
    @GetMapping
    @ApiOperation(value = "查询所有员工数据")
    public List<Systemdictionarytype> findAll(){
        return systemdictionarytypeService.findAll();
    }

    // 添加
    @PutMapping
    public AjaxResult addOrUpdate(@RequestBody Systemdictionarytype systemdictionarytype){
        if (null == systemdictionarytype.getId()){
            // 添加
            systemdictionarytypeService.add(systemdictionarytype);
        }else {
            // 修改
            systemdictionarytypeService.update(systemdictionarytype);
        }
        return AjaxResult.me().success();
    }


    // 分页查询
    @PostMapping
    @LogAnno(method = "queryByPage", methodDes = "分页查询部门")
    public PageList<Systemdictionarytype> queryByPage(@RequestBody SystemdictionarytypeQuery query){
        return systemdictionarytypeService.queryByPage(query);
    }

    // 删除
    @DeleteMapping("/{id}")
    public AjaxResult delete(@PathVariable("id") Long id){
        systemdictionarydetailService.delByTypeId(id);
        systemdictionarytypeService.delete(id);
        return AjaxResult.me().success();
    }


    // 批量删除
    @PatchMapping
    public AjaxResult batchDel(@RequestBody List<Long> ids){
        systemdictionarytypeService.batchDel(ids);
        return AjaxResult.me().success();
    }
}
